package org.blogwu.learn.multithread.chapter3.demo9;

import java.util.concurrent.locks.LockSupport;

/**
 * 测试park 会不会释放锁.
 *
 * @author hyf
 * @date 2018-09-23
 **/
public class Main3 {

    public static void main(String[] args) throws InterruptedException {
        SupportTest s1 = new SupportTest("s1", 1);
        SupportTest s2 = new SupportTest("s2", 2);
        s1.start();
        Thread.sleep(1000);
        s2.start();

    }
}

class SupportTest extends Thread {
    static Object o1 = new Object();
    int rz = 0;

    public SupportTest(String name, int rz) {
        super(name);
        this.rz = rz;
    }

    @Override
    public void run() {
        System.out.println(getName() + "  开始进入临界区");
        synchronized (o1) {
            if (rz == 1) {
                System.out.println(getName() + "  开始暂停");
                LockSupport.park();
                System.out.println(getName() + "  暂停完毕");
            }
        }
        System.out.println(getName() + "  运行完毕");
    }
}
